﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using DGM.Objects.General;

namespace DGM.Util.Helpers.Google
{
    public static class TranslateHelper
    {
	    private const string ApiKey = "AIzaSyBx4jFUTqQOVvELOdLjIdYBBsfm41L9vkc";
        public static string TranslateToEnglish(string text)
        {

					string q = string.Format("https://www.googleapis.com/language/translate/v2?key={0}&format=text&q={1}&target=en", ApiKey, HttpUtility.UrlEncode(text));

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(q);
            webRequest.Timeout = -1;
            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

            StreamReader responseStream = new StreamReader(webResponse.GetResponseStream());

            string data = "";

            while (responseStream.EndOfStream == false)
            {
                data = data + responseStream.ReadLine();
            }

           return data;
        }
    }
}
